<?php
// +----------------------------------------------------------------------
// | Tplay [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 听雨 < 389625819@qq.com >
// +----------------------------------------------------------------------


namespace app\admin\controller;

use \think\Db;
use \think\Cookie;
use app\admin\model\Score as scoreModel;//学生信息模型
use app\admin\model\AdminMenu;
use app\admin\controller\User;
class Score extends User
{
    /**
     * 学生积分列表
     * @return [type] [description]
     */
    public function index()
    {
        //实例化积分模型
        $model = new scoreModel();
        $sname='';
        $post = $this->request->post();
        if (isset($post['xid']) and $post['xid'] > 0) {
            $where['xid'] = $post['xid'];
        }
        if (isset($post['cid']) and $post['cid'] > 0) {
            $where['cid'] = $post['cid'];
        }
        $reason = empty($where) ? $model->order('reid asc')->paginate(4) : $model->where($where)->order('reid asc')->paginate(4);

      // print_r($reason);
        //$reason=Db::name("score")->sum('fid');
        $stu=Db::name("stu")->select();
        $school=Db::name("school")->select();
        $cla=Db::name("cla")->select();
        $this->assign('school',$school);
        $this->assign('stu',$stu);
        $this->assign('reason',$reason);
        $this->assign('cla',$cla);
        $this->assign('sname',$sname);
       return $this->fetch();
    }
    //联动调用方法
    public function cla()
    {
        if($this->request->isAjax()) {
            $xid = $this->request->has('xid') ? $this->request->param('xid', 0, 'intval') : 0;
            $cla=Db::name("cla")->where('xid',$xid)->select();
            $str='<option>-请选择班级-</option>';
            foreach ($cla as $key => $value){
                $str.='<option value="'.$value['cid'].'">'.$value['cname'].'</option>';
            }
            return $str;
        }
    }
    public function stu()
    {
        if($this->request->isAjax()) {
            $cid = $this->request->has('cid') ? $this->request->param('cid', 0, 'intval') : 0;
            $stu=Db::name("stu")->where('cid',$cid)->select();
            $str='<option>-请选择学生-</option>';
            foreach ($stu as $key => $value){
                $str.='<option value="'.$value['sid'].'">'.$value['sname'].'</option>';
            }
            return $str;
        }
    }
}
?>